package com.marketing.auth.dto;

import com.marketing.auth.entity.User;

/**
 * 登录响应DTO
 */
public class LoginResponse {
    
    private Boolean success;
    private String message;
    private String token;
    private String tokenType = "Bearer";
    private Long expiresIn; // 过期时间（秒）
    private Object userInfo; // 可以是UserInfoDto或UserPermissionDto
    private Integer serverPort; // 用于负载均衡验证
    
    public LoginResponse() {}
    
    public LoginResponse(Boolean success, String message) {
        this.success = success;
        this.message = message;
    }
    
    public LoginResponse(Boolean success, String message, String token, Long expiresIn, User user) {
        this.success = success;
        this.message = message;
        this.token = token;
        this.expiresIn = expiresIn;
        if (user != null) {
            this.userInfo = convertToDto(user);
        }
    }
    
    public LoginResponse(Boolean success, String message, String token, Long expiresIn, User user, Integer serverPort) {
        this.success = success;
        this.message = message;
        this.token = token;
        this.expiresIn = expiresIn;
        this.serverPort = serverPort;
        if (user != null) {
            this.userInfo = convertToDto(user);
        }
    }
    
    public LoginResponse(Boolean success, String message, String token, Long expiresIn, UserInfoDto userInfo, Integer serverPort) {
        this.success = success;
        this.message = message;
        this.token = token;
        this.expiresIn = expiresIn;
        this.userInfo = userInfo;
        this.serverPort = serverPort;
    }
    
    public LoginResponse(Boolean success, String message, String token, Long expiresIn, UserPermissionDto userPermissionDto, Integer serverPort) {
        this.success = success;
        this.message = message;
        this.token = token;
        this.expiresIn = expiresIn;
        this.userInfo = userPermissionDto;
        this.serverPort = serverPort;
    }
    
    private UserInfoDto convertToDto(User user) {
        UserInfoDto dto = new UserInfoDto();
        dto.setId(user.getId());
        dto.setUsername(user.getUsername());
        dto.setEmail(user.getEmail());
        dto.setNickname(user.getNickname());
        dto.setAvatar(user.getAvatar());
        dto.setPhone(user.getPhone());
        dto.setStatus(user.getStatus());
        dto.setRole(user.getRole());
        dto.setDepartment(user.getDepartment());
        dto.setPosition(user.getPosition());
        dto.setLoginCount(user.getLoginCount());
        return dto;
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public String getTokenType() {
        return tokenType;
    }

    public void setTokenType(String tokenType) {
        this.tokenType = tokenType;
    }

    public Long getExpiresIn() {
        return expiresIn;
    }

    public void setExpiresIn(Long expiresIn) {
        this.expiresIn = expiresIn;
    }

    public Object getUserInfo() {
        return userInfo;
    }

    public void setUserInfo(Object userInfo) {
        this.userInfo = userInfo;
    }

    public Integer getServerPort() {
        return serverPort;
    }

    public void setServerPort(Integer serverPort) {
        this.serverPort = serverPort;
    }

    /**
     * 用户信息内部类（不包含敏感信息）
     */
    public static class UserInfo {
        private Long id;
        private String username;
        private String email;
        private String nickname;
        private String avatar;
        private Integer status;

        public UserInfo() {}

        public UserInfo(User user) {
            this.id = user.getId();
            this.username = user.getUsername();
            this.email = user.getEmail();
            this.nickname = user.getNickname();
            this.avatar = user.getAvatar();
            this.status = user.getStatus();
        }

        // Getters and Setters
        public Long getId() {
            return id;
        }

        public void setId(Long id) {
            this.id = id;
        }

        public String getUsername() {
            return username;
        }

        public void setUsername(String username) {
            this.username = username;
        }

        public String getEmail() {
            return email;
        }

        public void setEmail(String email) {
            this.email = email;
        }

        public String getNickname() {
            return nickname;
        }

        public void setNickname(String nickname) {
            this.nickname = nickname;
        }

        public String getAvatar() {
            return avatar;
        }

        public void setAvatar(String avatar) {
            this.avatar = avatar;
        }

        public Integer getStatus() {
            return status;
        }

        public void setStatus(Integer status) {
            this.status = status;
        }
    }
}